package com.cn.ZhiKeDianShang.util.Netdialog;


import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;


import androidx.appcompat.app.AppCompatDialog;

import com.cn.ZhiKeDianShang.util.Netdialog.Dialog.DialogAssigner;
import com.cn.ZhiKeDianShang.util.Netdialog.Dialog.config.ConfigBean;

/**
 * Created by Administrator on 2016/5/4 0004.
 */
public class StyledDialog {

    //android.support.v7.app.

    public static Context context;

    private static int singleChosen;

    private static DialogInterface loadingDialog;//缓存加载中的dialog,便于以后可以不需要对象就让它消失

    private static boolean isMiUi8 = false;//miui8用非activity的Context时,无法以TYPE_TOAST的形式弹出对话框.没有好的解决办法.....

    //注册一下，要在哪个页面上显示
    public static void init(Context context) {
        StyledDialog.context = context;
    }

    public static void setLoadingObj(DialogInterface loading) {
        dismiss(loadingDialog);
        loadingDialog = loading;
    }


    /**
     * 一键让loading消失.
     */
    public static void dismissLoading() {
        if (loadingDialog != null) {
            dismiss(loadingDialog);
            loadingDialog = null;
        }
    }


    public static void dismiss(DialogInterface... dialogs) {
        if (dialogs != null && dialogs.length > 0) {
            for (DialogInterface dialog : dialogs) {
                if (dialog instanceof Dialog) {
                    Dialog dialog1 = (Dialog) dialog;
                    if (dialog1.isShowing()) {
                        dialog1.dismiss();
                    }
                } else if (dialog instanceof AppCompatDialog) {
                    AppCompatDialog dialog2 = (AppCompatDialog) dialog;
                    if (dialog2.isShowing()) {
                        dialog2.dismiss();
                    }
                }
            }

        }
    }

    public static ConfigBean buildLoading(Context mcontext, CharSequence msg) {
        return DialogAssigner.getInstance().assignLoading(mcontext, msg, true, false);
    }

}
